package whf.framework.util;

import java.io.Serializable;
import java.util.Set;

import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 简单的名值对对象
 * @author wanghaifeng
 * @create Mar 29, 2007 10:36:26 PM
 * 
 */
@SuppressWarnings("serial")
public class Pair<K, V> implements Serializable{
	/**
	 * @property String:name
	 */
	private K text;
	
	/**
	 * @property String:value
	 */
	private V value;

	public Pair(K name, V value){
		this.text = name;
		this.value = value;
	}
	
	public K getFirst(){
		return text;
	}
	
	public V getSecond(){
		return value;
	}
	
	/**
	 * @return Returns the name.
	 */
	public K getText() {
		return text;
	}

	/**
	 * @param name The name to set.
	 */
	public void setText(K name) {
		this.text = name;
	}

	/**
	 * @return Returns the value.
	 */
	public V getValue() {
		return value;
	}

	/**
	 * @param value The value to set.
	 */
	public void setValue(V value) {
		this.value = value;
	}
	
	public int hashCode(){
		return HashCodeBuilder.reflectionHashCode(this);
	}
	
	public boolean equals(Object object){
		if(object == null) return false;
		return this.hashCode() == object.hashCode();
	}
	
	public static void main(String[] args) throws Exception{
		Pair<Integer, Integer> p1 = new Pair<Integer, Integer>(0, 0);
		Pair<Integer, Integer> p2 = new Pair<Integer, Integer>(0, 0);
		Set<Pair<Integer, Integer>> set = Utils.newHashSet();
		set.add(p1);
		set.add(p2);
		System.out.println(set);
		System.out.println(p1 == p2);
	}
}
